package com.igeekhome.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.igeekhome.biz.WorkloadStatisticsService;
import com.igeekhome.pojo.WorkloadStatistics;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 * 工作量统计 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2021-03-16
 */
@Controller
@RequestMapping("/workloadStatistics")
public class WorkloadStatisticsController {
    @Autowired
    private WorkloadStatisticsService workloadStatisticsService;

    @RequestMapping("/workloadstatistics")//gonguzooliang
    public String index(Model model,@RequestParam("current") Integer current,@RequestParam("size") Integer size)
    {

        model.addAttribute("main","工作量统计");
        initWorkloadStatistics(model,current,size);
        return "workloadstatistics";
    }


    public void initWorkloadStatistics(Model model,Integer current,Integer size) {

        IPage<WorkloadStatistics> page = new Page<>(current, size);
        IPage<WorkloadStatistics> page1 = this.workloadStatisticsService.page(page);

        List<WorkloadStatistics> list = page1.getRecords();
        long pageCount = page1.getPages();
        model.addAttribute("main","工作量统计");
        model.addAttribute("pageCount",pageCount);
        model.addAttribute("list", list);
    }

    @RequestMapping("/del")
    public String del(Model model,WorkloadStatistics workloadStatistics,@RequestParam("current") Integer current,@RequestParam("size") Integer size)
    {
        this.workloadStatisticsService.removeById(workloadStatistics.getId());
        initWorkloadStatistics(model,current,size);
        return "workloadstatistics";
    }
    @RequestMapping("/update")
    public String update(Model model, WorkloadStatistics workloadStatistics,@RequestParam("current") Integer current,@RequestParam("size") Integer size)
    {
        workloadStatistics=this.workloadStatisticsService.getById(workloadStatistics.getId());
        //根据id将对象查询
        model.addAttribute("current",current);
        model.addAttribute("size",size);
        model.addAttribute("workloadStatistics",workloadStatistics);
        model.addAttribute("main","工作量统计");
        return "updateworkloadstatistics";

    }
    @RequestMapping("/updcom")
    public String updcom(Model model, WorkloadStatistics workloadStatistics,@RequestParam("current") Integer current,@RequestParam("size") Integer size)
    {
//       System.out.println("111");
        this.workloadStatisticsService.saveOrUpdate(workloadStatistics);
        initWorkloadStatistics(model,current,size);
        return "workloadstatistics";
    }


    public String index2(Model model, HttpSession session)
    {
        model.addAttribute("main","工作量统计");
        return "workloadstatistics";
//        gongzuoliang

    }




    @RequestMapping("/message")
    public String index3(Model model,@RequestParam("current") Integer current,@RequestParam("size") Integer size)
    {
        initWorkloadStatistics(model,current,size);
        return "workload";
    }

}

